package cn.sinata.wanglin.neighbor.activity;

import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.xilada.xldutils.activitys.RecyclerListActivity;
import com.xilada.xldutils.adapter.BaseRecyclerAdapter;
import com.xilada.xldutils.utils.ActivityUtil;
import com.xilada.xldutils.view.SwipeRefreshRecyclerLayout;

import java.util.ArrayList;

import cn.sinata.wanglin.adapter.GroupMemberAdapter;
import cn.sinata.wanglin.model.Member;
import cn.sinata.wanglin.village.activity.AllUserInfoActivity;

public class GroupMembersActivity extends RecyclerListActivity {

    private GroupMemberAdapter groupMemberAdapter;
    private ArrayList<Member> members = new ArrayList<>();
    private boolean isOwner = false;
    private String id;
    private String account;

    @Override
    protected void initView() {
        super.initView();
        setTitle("群成员");

        isOwner = getIntent().getBooleanExtra("isOwner",false);
        ArrayList<Member> datas = getIntent().getParcelableArrayListExtra("data");
        id = getIntent().getStringExtra("id");
        account = getIntent().getStringExtra("account");

        groupMemberAdapter.setGroupInfo(id,account,isOwner);
        if (datas != null) {
            members.addAll(datas);
            groupMemberAdapter.notifyDataSetChanged();
        }
    }

    @Override
    protected SwipeRefreshRecyclerLayout.Mode getMode() {
        return SwipeRefreshRecyclerLayout.Mode.None;
    }

    @Override
    protected RecyclerView.Adapter setAdapter() {
        groupMemberAdapter = new GroupMemberAdapter(members);
        groupMemberAdapter.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                ActivityUtil.create(mContext)
                        .go(AllUserInfoActivity.class)
                        .put("friendID",members.get(position).getUserID())
                        .start();
            }
        });
        return groupMemberAdapter;
    }

    @Override
    public void finish() {
        if (groupMemberAdapter!=null && groupMemberAdapter.isEditMember()) {
            setResult(RESULT_OK);
        }
        super.finish();
    }
}
